﻿#foreach($u in $TableInfos)
#beforeall
#each
//编辑${u.TabCaption}
Edit${u.TabName} = function(id) {
    var Edit${u.TabName}Form = Ext.create("Ext.form.Panel", {
        width: 360,
        height: 450,
        autoScroll: true, 
        plain: true,
        layout: "anchor",
        defaultType: "textfield",
        labelWidth: 55,
        baseCls: "x-plain",
        defaults: { labelAlign: 'right', anchor: "90%", msgTarget: "side" },
        buttonAlign: "center",
        bodyStyle: "padding:0 0 0 0",
        items: [{
           #foreach($c in $u.ColumnInfos)  
#beforeall
#set($tbCount=0)#set( $listCount=$u.ColumnInfos.Count)
#each 
#set($tbCount=$tbCount+1)
#if($tbCount==$listCount)##最后一条
#if($c.TypeName=="bit")  
            name: "${c.ColumnName}",
            fieldLabel: "${c.DeText}",
            xtype: "combo",
            //传入后台真实值value field /value
            emptyText: '请选择',
            triggerAction: 'query',
            hiddenName: "M_IsSystem",
            readOnly: true,
            mode: "local",
            displayField: "show",
            valueField: "value",
            triggerAction: "all",
            value: "0",
            store: new Ext.data.SimpleStore({
                fields: ["show", "value"],
                data: [["是", "1"], ["否", "0"]]
            })
        }
#elseif($c.TypeName=="varchar")
            name: "${c.ColumnName}",
#if(${c.cisNull}!="True")
            fieldLabel: "<font color='red'>*</font>${c.DeText}",
            allowBlank: false,
            blankText: "${c.DeText}不能为空",
            regex: /^[\da-zA-Z]{1,9}$/,
            regexText: "请填写1～9个数字或字母"
#else
            fieldLabel: "${c.DeText}",
            regex: /^[\da-zA-Z]{0,9}$/,
            regexText: "请填写0～9个数字或字母"
#end
        }
#elseif($c.TypeName=="datetime")
            xtype:"datefield",
            name: "${c.ColumnName}",
#if(${c.cisNull}!="True")
            fieldLabel: "<font color='red'>*</font>${c.DeText}",
            allowBlank: false,
            blankText: "${c.DeText}不能为空",
#else
            fieldLabel: "${c.DeText}",
#end
        }
#elseif($c.TypeName=="nvarchar")
            name: "${c.ColumnName}",
#if(${c.cisNull}!="True")
            fieldLabel: "<font color='red'>*</font>${c.DeText}",
            allowBlank: false,
            blankText: "${c.DeText}不能为空",
            regex: /^[\da-zA-Z]{1,${c.Length}}$/,
            regexText: "请填写1～${c.Length}个数字或字母"
#else
            fieldLabel: "${c.DeText}",
            regex: /^[\da-zA-Z]{0,${c.Length}}$/,
            regexText: "请填写0～${c.Length}个数字或字母"
#end
        }
#elseif($c.TypeName=="int")
            name: "${c.ColumnName}",
#if(${c.cisNull}!="True")
            fieldLabel: "<font color='red'>*</font>${c.DeText}",
            allowBlank: false,
            blankText: "${c.DeText}不能为空",
            regex: /^[\d]{0,${c.Length}}$/,
            regexText: "请填写0～${c.Length}个数字"
#else
            fieldLabel: "${c.DeText}",
            regex: /^[\d]{1,${c.Length}}$/,
            regexText: "请填写1～${c.Length}个数字"
#end
        }
#elseif($c.TypeName=="tinyint")
            name: "${c.ColumnName}",
            fieldLabel: "${c.DeText}",
            xtype: "combo",
            //传入后台真实值value field /value
            emptyText: '请选择',
            triggerAction: 'query',
            hiddenName: "M_IsSystem",
            readOnly: true,
            mode: "local",
            displayField: "show",
            valueField: "value",
            triggerAction: "all",
            value: "0",
            store: new Ext.data.SimpleStore({
                fields: ["show", "value"],
                data: [["是", "1"], ["否", "0"]]
            })
        }
#else
            name: "${c.ColumnName}",
#if(${c.cisNull}!="True")
            fieldLabel: "<font color='red'>*</font>${c.DeText}",
            allowBlank: false,
            blankText: "${c.DeText}不能为空",
            regex: /^[\w]{1,${c.Length}}$/,
            regexText: "请填写1～${c.Length}个数字或字母"
#else
            fieldLabel: "${c.DeText}",
            regex: /^[\w]{0,${c.Length}}$/,
            regexText: "请填写0～${c.Length}个数字或字母"
#end
         }
#end
#else##不是第一个
#if($c.TypeName=="bit")
            name: "${c.ColumnName}",
            fieldLabel: "${c.DeText}",
            xtype: "combo",
            //传入后台真实值value field /value
            editable: false,
            anchor: '90%',
            value: 0,
            store: Ext.create('Ext.data.Store', {
                fields: ['show', 'value'],
                data: [
			        { "show": "是", "value": 1 },
			        { "show": "否", "value":0 }
			    ]
            }),
            queryMode: 'local',
            displayField: 'show',
            valueField: 'value'
        }, {
#elseif($c.TypeName=="datetime")
            xtype:"datefield",
            name: "${c.ColumnName}",
#if(${c.cisNull}!="True")
            fieldLabel: "<font color='red'>*</font>${c.DeText}",
            allowBlank: false,
            blankText: "${c.DeText}不能为空",
#else
            fieldLabel: "${c.DeText}",
#end
        }, {
#elseif($c.TypeName=="varchar")
            name: "${c.ColumnName}",
#if(${c.cisNull}!="True")
            fieldLabel: "<font color='red'>*</font>${c.DeText}",
            allowBlank: false,
            blankText: "${c.DeText}不能为空",
            regex: /^[\da-zA-Z]{1,9}$/,
            regexText: "请填写1～9个数字或字母"
#else
            fieldLabel: "${c.DeText}",
            regex: /^[\da-zA-Z]{0,9}$/,
            regexText: "请填写0～9个数字或字母"
#end
        }, {
#elseif($c.TypeName=="nvarchar")
            name: "${c.ColumnName}",
#if(${c.cisNull}!="True")
            fieldLabel: "<font color='red'>*</font>${c.DeText}",
            allowBlank: false,
            blankText: "${c.DeText}不能为空",
            regex: /^[\da-zA-Z]{1,${c.Length}}$/,
            regexText: "请填写1～${c.Length}个数字或字母"
#else
            fieldLabel: "${c.DeText}",
            regex: /^[\da-zA-Z]{0,${c.Length}}$/,
            regexText: "请填写0～${c.Length}个数字或字母"
#end
        }, {
#elseif($c.TypeName=="int")
            name: "${c.ColumnName}",
#if(${c.cisNull}!="True")
            fieldLabel: "<font color='red'>*</font>${c.DeText}",
            allowBlank: false,
            blankText: "${c.DeText}不能为空",
            regex: /^[\d]{0,${c.Length}}$/,
            regexText: "请填写0～${c.Length}个数字"
#else
            fieldLabel: "${c.DeText}",
            regex: /^[\d]{1,${c.Length}}$/,
            regexText: "请填写1～${c.Length}个数字"
#end
        }, {
#elseif($c.TypeName=="tinyint")
            name: "${c.ColumnName}",
            fieldLabel: "${c.DeText}",
            xtype: "combo",
            //传入后台真实值value field /value
            editable: false,
            anchor: '90%',
            value: 0,
            store: Ext.create('Ext.data.Store', {
                fields: ['show', 'value'],
                data: [
			        { "show": "是", "value": 1 },
			        { "show": "否", "value":0 }
			    ]
            }),
            queryMode: 'local',
            displayField: 'show',
            valueField: 'value'
        }, {
#else
            name: "${c.ColumnName}",

#if(${c.cisNull}!="True")
            fieldLabel: "<font color='red'>*</font>${c.DeText}",
            allowBlank: false,
            blankText: "${c.DeText}不能为空",
            regex: /^[\w]{1,${c.Length}}$/,
            regexText: "请填写1～${c.Length}个数字或字母"
#else
            fieldLabel: "${c.DeText}",
            regex: /^[\w]{0,${c.Length}}$/,
            regexText: "请填写0～${c.Length}个数字或字母"
#end 
         }, {
#end
#end
#end
			]
    });

    var Edit${u.TabName}Win = new Ext.Window({
        title: "修改${u.TabCaption}",
        width: 400,
        height: 450,
        plain: true,
        layout: "fit",
        //iconCls: "addicon",
        //不可以随意改变大小
        resizable: false,
        //是否可以拖动
        //draggable:false,
        defaultType: "textfield",
        //labelWidth: 100,
        collapsible: true, //允许缩放条
        closeAction: 'hide',
        closable: true,
        //弹出模态窗体
        modal: 'true',
        buttonAlign: "center",
        bodyStyle: "padding:10px 0 0 15px",
        items: [Edit${u.TabName}Form],
        listeners: {
            "show": function() {
                if (id && id != "") {
                    //加载表单数据
                    Edit${u.TabName}Form.form.load(
                                {
                                    url: "/manager/${u.TabName}/Look/" + id,
                                    method: "get",
                                    success: function(form, action) {

                                    },
                                    failure: function(form, action) {
                                        Ext.Msg.alert("提示信息", "对不起加载数据失败!请联系管理员");
                                    }
                                }
                    );
                }
            }
        },
        buttons: [{
            text: "保存信息",
            minWidth: 70,
            handler: function() {
                //alert(Edit${u.TabName}Form.getForm().isValid())
                if (Edit${u.TabName}Form.getForm().isValid()) {
                    //弹出效果 Ext.MessageBox.alert("asdf");
                    Ext.MessageBox.show
                                (
                                    {
                                        msg: '正在保存，请稍等...',
                                        progressText: 'Saving...',
                                        width: 300,
                                        wait: true,
                                        waitConfig: { interval: 200 },
                                        icon: 'download',
                                        animEl: 'saving'
                                    }
                                );
                    setTimeout(function() { }, 1000);
                    Edit${u.TabName}Form.form.submit({
                        url: "/manager/${u.TabName}/Update/" + id,
                        method: "POST",
                        success: function(form, action) {
                            //成功后
                            var flag = action.result.success;
                            if (flag == "true") {
                                ${u.TabName}Store.loadPage(1);
                                Ext.MessageBox.alert("恭喜", "修改成功!");
                                Edit${u.TabName}Win.hide();
                            }
                            else {
                                var message = action.result.message;
                                if (message) {
                                    Ext.MessageBox.alert("修改失败!", message);
                                }
                                else {
                                    Ext.MessageBox.alert("提示!", "修改失败!");
                                    Edit${u.TabName}Win.hide();
                                }

                            }
                        },
                        failure: function(form, action) {
                            Ext.MessageBox.alert("提示!", "修改失败!");
                            Edit${u.TabName}Win.hide();
                        }
                    });
                }
            }
        }, {
            text: "重置",
            minWidth: 70,
            qtip: "重置数据",
            handler: function() {
                //加载表单数据
                Edit${u.TabName}Form.getForm().reset();
                Edit${u.TabName}Form.form.load(
                                {
                                    url: "/manager/${u.TabName}/Look/" + id,
                                    method: "get",
                                    success: function(form, action) {
                                    },
                                    failure: function(form, action) {
                                        //Ext.Msg.alert("提示信息","对不起加载数据失败!请联系管理员");
                                    }
                                }
                    );
            }
        }, {
            text: "取 消",
            minWidth: 70,
            handler: function() {
                Edit${u.TabName}Win.hide();
            }

}]

        });

        Edit${u.TabName}Win.show();
    }
#end
